<script setup>
import { onMounted, onUnmounted ,reactive} from "vue";
// import AMapLoader from "@amap/amap-jsapi-loader";

let map = null;
let state = reactive({
  inputValue:'',
  jwD:{
    address:'',
    name:'',
    district:'',
    lat:'',//维度
    lng:''
  }
})
const emit = defineEmits(['getAddress']);
onMounted(() => {
  // AMapLoader.load({
  //   key: "257983ac264f9d17c30539b742c410f9", // 申请好的Web端开发者Key，首次调用 load 时必填
  //   version: "2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
  //   plugins:['AMap.AutoComplete']
  // })
  //   .then((AMap) => {
  //     AMap.plugin('AMap.AutoComplete', function () {
  //       const autoComplete = new AMap.Autocomplete({
  //         input: 'input'
  //       });
  //       console.log(autoComplete);
  //       autoComplete.on('select', function (e) {
  //         // 处理用户选择搜索建议时的逻辑
  //         console.log(e);
  //         map.setCenter(e.poi.location);
  //         map.setZoom(17);
  //         map.setHighlight(e.poi.location);
  //         state.jwD.lat=e.poi.location.lat,//维度
  //         state.jwD.lng=e.poi.location.lng//经度
  //         state.jwD.name = e.poi.name
  //         state.jwD.address =e.poi.district + e.poi.address
  //         emit('getAddress',state.jwD)
  //       });
  //     });
  //     map = new AMap.Map("container", {
  //       // 设置地图容器id
  //       viewMode: "3D", // 是否为3D地图模式
  //       zoom: 11, // 初始化地图级别
  //       center: [116.397428, 39.90923], // 初始化地图中心点位置
  //     });
  //   })
  //   .catch((e) => {
  //     console.log(e);
  //   });
});

onUnmounted(() => {
  map?.destroy();
});
</script>

<template>
  <div>
    <div class="biaoshi">
      <span>地址：</span>
      <el-input class="shuru" v-model="state.inputValue" id='input'></el-input>
      <div>当前选择的位置：{{state.jwD.name}}</div>
    </div>
    <div id="container"></div>
  </div>
</template>

<style scoped lang='scss'>
#container {
  width: 100%;
  height: 400px;
}
.biaoshi{
  display: flex;
  margin-bottom: 10px;
  align-items: center;
  .shuru{
    width: 50%;
    margin-right: 20px;
  }
}
</style>
